package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-07-28 16:48
 */
@Controller
public class ItemHtmlController {


    @Autowired
    private ItemFeignClient itemFeignClient;


    /**
     * 渲染商品详情页面
     *
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String itemHtml(Model model, @PathVariable("skuId") Long skuId) {
        //1.远程调用详情服务获取渲染页面所需数据模型
        Result<Map> result = itemFeignClient.getItemInfo(skuId);

        //2.通过Model对象设置数据模型 参数类型是Map
        model.addAllAttributes(result.getData());

        //3.返回当前详情页模板名称
        return "/item/item";
    }
}
